home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c / 9 < prev    next >
Internet Message Format  |  1996-08-06  |  4KB

  1. Path: cygnus.com!not-for-mail
  2. From: rfg@monkeys.com (Ronald F. Guilmette)
  3. Newsgroups: comp.std.unix,comp.std.c
  4. Subject: A question about FILEs (with relevance to POSIX threads).
  5. Followup-To: comp.std.unix
  6. Date: 1 Jan 1996 16:34:02 -0800
  7. Organization: Infinite Monkeys & Co.
  8. Sender: sef@cygnus.com
  9. Approved: sef@cygnus.com (Moderator, Sean Eric Fagan)
  10. Message-ID: <4c9uhq$s82@cygnus.com>
  11. NNTP-Posting-Host: cygnus.com
  12. X-Submissions: std-unix@uunet.uu.net
  13.  
  14. Submitted-by: rfg@monkeys.com (Ronald F. Guilmette)
  15.  
  16. Greetings all.
  17.  
  18. I'd like to start out the new year with a simple (but perhaps obscure)
  19. question about FILE structures.
  20.  
  21. This is not so much a question of what the standard says as it is a
  22. question of why traditional implementations are the way they are.
  23. (Lest Norman or anyone else remind me, I _am_ aware that such ques-
  24. tions are normally considered somewhat off-topic for comp.std.c, but
  25. please bear with me.  I need to put this question to _implementors_,
  26. and this is the best forum to obtain the ear of such people.)
  27.  
  28. Quite simply, I'd like to know why traditional implementations of the
  29. C language (in both its ANSI/ISO and pre-ANSI/ISO flavors) are in the
  30. habit of statically allocating a fixed length array of FILE structures
  31. (for the program to use) rather than (say) using malloc to allocate a
  32. new FILE structure each time a new one is needed (e.g. during a call
  33. to fopen, freopen, or fdopen).
  34.  
  35. I really don't understand the rationale for the fixed length, static-
  36. ally allocated array of FILE structures at all, although I'm sure that
  37. there must have been a good reason for it at some point in time.  (In
  38. the modern era of reentrancy however, where we eschew global data, it
  39. does seem to me that the traditional implementation technique of static-
  40. ally allocating a global set of FILE structures is an anachronism which
  41. is no longer viable.  Does the POSIX 1003.1c standard reach the same
  42. conclusion?  I wish I knew.  Unfortunately, I don't actually have a
  43. copy... A situation which I hope to rectify in the near future.)
  44.  
  45. Obviously, the motivation for the question above relates to POSIX 1003.1c,
  46. i.e. POSIX threads.  It occurs to me that it might be easily possible
  47. for each independent POSIX thread in a given program to have its own
  48. independent stdin, stdout, and stderr FILE structures.  But implement-
  49. ing this simple, and potentially very useful bit of functionality
  50. appears to be problematic in the context of traditional implementations
  51. of the stdio functions, e.g. implementations which utilize a fixed-length
  52. statically allocated array of FILE structures and implementations which
  53. define the stdin, stdout, and stderr macros to expand merely to the
  54. addresses of the 0'th, 1'st, and 2'nd elements of this static FILE array
  55. (respectively).
  56.  
  57. I can easily envision an alternative implementation in which these three
  58. macros expand to three thread-specific data values (i.e. FILE pointers)
  59. which in turn (potentially) point to three separate and independent
  60. thread-specific FILE structures.
  61.  
  62. I say ``potentially'' because I think it would make sense to have a
  63. newly spawned child thread share the pre-existing stdin, stdout, and
  64. stderr FILE structures with its parent, effectively inheriting these
  65. from the parent... a useful default which could subsequently be over-
  66. ridden for any given child thread.
  67.  
  68. I address my final question to the members of the POSIX 1003.1c committee:
  69.  
  70. Did you folks consider the possibility of allowing for thread-specific
  71. stdin, stdout, and stderr files?  Is such a possibility/capability already
  72. fully supported under POSIX 1003.1c?
  73. -- 
  74. -- Ron Guilmette, Roseville, CA -------- Infinite Monkeys & Co. ------------
  75. ---- E-mail: rfg@monkeys.com ----------- Purveyors of Compiler Test Suites -
  76. ------ Copyright (c) 1995 by Ronald F. Guilmette; All rights reserved. -----
  77.  
  78.  
  79. [ Note the crossposting and Followup-To: line... -- mod ]
  80.  
  81. Volume-Number: Volume 35, Number 74
  82.